
#ifndef dalvik_fmt_h
#define dalvik_fmt_h

#include "types.h"

typedef enum _dalvik_fmt{
fmt_00x,
fmt_10x,
fmt_12x,
fmt_11n,
fmt_11x,
fmt_10t,
fmt_20t,
fmt_20bc,
fmt_22x,
fmt_21t,
fmt_21s,
fmt_21h,
fmt_21c,
fmt_23x,
fmt_22b,
fmt_22t,
fmt_22s,
fmt_22c,
fmt_22cs,
fmt_30t,
fmt_32x,
fmt_31i,
fmt_31t,
fmt_31c,
fmt_35c,
fmt_35ms,
fmt_35mi,
fmt_3rc,
fmt_3rms,
fmt_3rmi,
fmt_51l,
fmt_max
} DALVIK_FMT;

typedef struct _insn_infmt_00x { 
uint16_t resved;
} INSN_INFMT_00x;

typedef struct _insn_infmt_10x { 
uint16_t op:8;
uint16_t any:8;
} INSN_INFMT_10x;

typedef struct _insn_infmt_12x { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
} INSN_INFMT_12x;

typedef struct _insn_infmt_11n { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
} INSN_INFMT_11n;

typedef struct _insn_infmt_11x { 
uint16_t op:8;
uint16_t AA:8;
} INSN_INFMT_11x;

typedef struct _insn_infmt_10t { 
uint16_t op:8;
uint16_t AA:8;
} INSN_INFMT_10t;

typedef struct _insn_infmt_20t { 
uint16_t op:8;
uint16_t any:8;
uint16_t AAAA;
} INSN_INFMT_20t;

typedef struct _insn_infmt_20bc { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_20bc;

typedef struct _insn_infmt_22x { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_22x;

typedef struct _insn_infmt_21t { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_21t;

typedef struct _insn_infmt_21s { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_21s;

typedef struct _insn_infmt_21h { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_21h;

typedef struct _insn_infmt_21c { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
} INSN_INFMT_21c;

typedef struct _insn_infmt_23x { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BB:8;
uint16_t CC:8;
} INSN_INFMT_23x;

typedef struct _insn_infmt_22b { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BB:8;
uint16_t CC:8;
} INSN_INFMT_22b;

typedef struct _insn_infmt_22t { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
uint16_t CCCC;
} INSN_INFMT_22t;

typedef struct _insn_infmt_22s { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
uint16_t CCCC;
} INSN_INFMT_22s;

typedef struct _insn_infmt_22c { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
uint16_t CCCC;
} INSN_INFMT_22c;

typedef struct _insn_infmt_22cs { 
uint16_t op:8;
uint16_t A:4;
uint16_t B:4;
uint16_t CCCC;
} INSN_INFMT_22cs;

typedef struct _insn_infmt_30t { 
uint16_t op:8;
uint16_t any:8;
uint16_t AAAAlo;
uint16_t AAAAhi;
} INSN_INFMT_30t;

typedef struct _insn_infmt_32x { 
uint16_t op:8;
uint16_t any:8;
uint16_t AAAA;
uint16_t BBBB;
} INSN_INFMT_32x;

typedef struct _insn_infmt_31i { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBBlo;
uint16_t BBBBhi;
} INSN_INFMT_31i;

typedef struct _insn_infmt_31t { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBBlo;
uint16_t BBBBhi;
} INSN_INFMT_31t;

typedef struct _insn_infmt_31c { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBBlo;
uint16_t BBBBhi;
} INSN_INFMT_31c;

typedef struct _insn_infmt_35c { 
uint16_t op:8;
uint16_t G:4;
uint16_t A:4;
uint16_t BBBB;
uint16_t C:4;
uint16_t D:4;
uint16_t E:4;
uint16_t F:4;
} INSN_INFMT_35c;

typedef struct _insn_infmt_35ms { 
uint16_t op:8;
uint16_t G:4;
uint16_t A:4;
uint16_t BBBB;
uint16_t C:4;
uint16_t D:4;
uint16_t E:4;
uint16_t F:4;
} INSN_INFMT_35ms;

typedef struct _insn_infmt_35mi { 
uint16_t op:8;
uint16_t G:4;
uint16_t A:4;
uint16_t BBBB;
uint16_t C:4;
uint16_t D:4;
uint16_t E:4;
uint16_t F:4;
} INSN_INFMT_35mi;

typedef struct _insn_infmt_3rc { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
uint16_t CCCC;
} INSN_INFMT_3rc;

typedef struct _insn_infmt_3rms { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
uint16_t CCCC;
} INSN_INFMT_3rms;

typedef struct _insn_infmt_3rmi { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBB;
uint16_t CCCC;
} INSN_INFMT_3rmi;

typedef struct _insn_infmt_51l { 
uint16_t op:8;
uint16_t AA:8;
uint16_t BBBBlo;
uint16_t BBBBmilo;
uint16_t BBBBmihi;
uint16_t BBBBhi;
} INSN_INFMT_51l;



typedef struct _ins_info{
 DALVIK_FMT fmt;
 int length;
 int ip;
 unsigned short * code;
} INSN_INFO,*PINSN_INFO;

extern unsigned insn_len_of_fmt[]; 
   

void print_fmt(PINSN_INFO p_insn);
unsigned insn_len_by_fmt(DALVIK_FMT fmt){return fmt<fmt_max?insn_len_of_fmt[fmt]:0;}

#endif// dalvik_fmt_h
